package fun.diaoer.config.security;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;

import fun.diaoer.common.Contants;
import fun.diaoer.common.JsonResult;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class DiaoerAuthenticationEntryPoint implements AuthenticationEntryPoint {

	@Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
		log.error("未登录");
		JsonResult<String> jr=new JsonResult<>();
		jr.setCode(101);
		jr.setStatus(false);
		Contants.buildLoginResponse(request, response);
		jr.setMsg("未登录");
		response.getWriter().write(JSON.toJSONString(jr));
		//response.sendError(HttpServletResponse.SC_FORBIDDEN,"无权访问哦！");
    }

}
